package com.jz.commom.api.dto.response;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class CommonResult<T> implements Serializable {
    /**
     * 成功失败标志 0，-1
     */
    private Integer code;
    /**
     * 成功失败消息
     */
    private String message;
    /**
     * 返回数据
     */
    private T data;

    /**
     * 成功标志
     */
    private static final Integer SUCCESS = 0;
    /**
     * 失败标志
     */
    private static final Integer FAIL = -1;

    public static <T> CommonResult<T> success(T data){
        return new CommonResult<T>(SUCCESS,null,data);
    }

    public static <T> CommonResult<T> success(String message, T data){
        return new CommonResult<T>(SUCCESS,message,data);
    }

    public static <T> CommonResult<T> fail(T data){
        return new CommonResult<T>(FAIL,null,data);
    }

    public static <T> CommonResult<T> fail(String message, T data){
        return new CommonResult<T>(FAIL,message,data);
    }

}
